package com.mlc.mlcitems.skills;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Transformation;
import org.joml.Vector3f;

import static com.mlc.mlcitems.Mlcitems.instance;
import static com.mlc.mlcitems.damage.arrowdamage.damageone;
import static com.mlc.mlcitems.itemmodelloader.electromballmodel;
import static com.mlc.mlcitems.itemmodelloader.smallfireballmodel;
import static com.mlc.mlcitems.particle.arrowparticle.spawnDRIPPING_LAVA;
import static com.mlc.mlcitems.particle.arrowparticle.spawnLAVA;
import static com.mlc.mlcitems.tracks.arrowtracks.*;

public class arrow {
    public static void smallfireball(Player player, Location location){
        ArmorStand armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
        armorStand.setVisible(false);
        armorStand.setInvulnerable(true);
        armorStand.setSmall(true);
        armorStand.setGravity(false);
        location.setY(location.getY()+1.62);
        armorStand.teleport(location);
        armorStand.setCollidable(false);
        armorStand.getEquipment().setHelmet(smallfireballmodel());
        armorStand.setRotation(location.getYaw(),location.getPitch());
        moveinline(armorStand,0.7);
        spawnDRIPPING_LAVA(armorStand);
        spawnLAVA(armorStand);
        damageone(player,armorStand,10,0.3);
        Bukkit.getScheduler().scheduleSyncDelayedTask(instance, armorStand::remove, 400L);

//        TextDisplay textDisplay = (TextDisplay) location.getWorld().spawnEntity(location, EntityType.TEXT_DISPLAY);
//        textDisplay.setTextOpacity((byte) 4);
//        textDisplay.setBackgroundColor(Color.fromRGB(245, 110, 77));
//        textDisplay.text(Component.text("66").color(TextColor.color(245, 110, 77)));
//        textDisplay.setViewRange(100);
//        textDisplay.setBillboard(Display.Billboard.CENTER);
    }

    public static void fireballaoe(Player player, Location location){
        ArmorStand armorStand = (ArmorStand) location.getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
        armorStand.setVisible(false);
        armorStand.setInvulnerable(true);
        armorStand.setSmall(true);
        armorStand.setGravity(false);
        location.setY(location.getY()+1.62);
        armorStand.teleport(location);
        armorStand.setCollidable(false);
        armorStand.getEquipment().setHelmet(smallfireballmodel());
        armorStand.setRotation(location.getYaw(),location.getPitch());
        spawnDRIPPING_LAVA(armorStand);
        spawnLAVA(armorStand);
        moveinlineaoe(player,armorStand,0.7,0.3,10,0.5);
        Bukkit.getScheduler().scheduleSyncDelayedTask(instance, armorStand::remove, 400L);

//        TextDisplay textDisplay = (TextDisplay) location.getWorld().spawnEntity(location, EntityType.TEXT_DISPLAY);
//        textDisplay.setTextOpacity((byte) 4);
//        textDisplay.setBackgroundColor(Color.fromRGB(245, 110, 77));
//        textDisplay.text(Component.text("66").color(TextColor.color(245, 110, 77)));
//        textDisplay.setViewRange(100);
//        textDisplay.setBillboard(Display.Billboard.CENTER);
    }
    public static void electromball(Player player, Location location){
        ItemDisplay itemDisplay = (ItemDisplay) location.getWorld().spawnEntity(location, EntityType.ITEM_DISPLAY);
        itemDisplay.setInvulnerable(true);
        itemDisplay.setGravity(false);
        Transformation transformation = new Transformation(
                new Vector3f(0, 0, 0),
                new org.joml.Quaternionf(),
                new Vector3f(1.7F, 1.7F, 1.7F),
                new org.joml.Quaternionf()
        );

        // 应用变换
        itemDisplay.setTransformation(transformation);
        location.setY(location.getY()+1.62);
        itemDisplay.teleport(location);
        itemDisplay.setItemStack(electromballmodel());
        itemDisplay.setRotation(location.getYaw(),location.getPitch());
        movethrough(itemDisplay,2.5);
        damageone(player,itemDisplay,10,1);
        Bukkit.getScheduler().scheduleSyncDelayedTask(instance, itemDisplay::remove, 400L);
    }
}
